function time_index = rslice_parse_datestring ( the_datestring, m_ocean_time )
% RSLICE_PARSE_DATESTRING:  turns the input string into an index

%
% If the input string is a single numeric value, then that is that.  
% Turn it into its numeric equivalent and return.
time_index = str2double(the_datestring);
if ~isnan ( time_index )
	return;
end


%
% Ok, try a few different date formats.
%
% First case catches someting like '1960-12-31 23:59:59'
try
	mday = datenum ( the_datestring, 'yyyy-mm-dd hh:MM:ss' );
	
	offset = abs(m_ocean_time - mday);
	time_index = find ( offset == min(offset) ) - 1;
	return

end

%
% Next case catches something like 'yyyy-mm-dd'
try
	mday = datenum ( the_datestring, 'yyyy-mm-dd' );
	
	offset = abs(m_ocean_time - mday);
	time_index = find ( offset == min(offset) ) - 1;
	return

end

%
% Next case catches someting like '19-May-2000'
try
	mday = datenum ( the_datestring, 'dd-mmm-yyyy' );
	
	offset = abs(m_ocean_time - mday);
	time_index = find ( offset == min(offset) ) - 1;
	return

end


time_index = NaN;
return
